<template>
  <div class="page-account"
       :style="backgroundImages ? { backgroundImage: 'url(' + backgroundImages + ')'} : { backgroundImage: 'url(' + backgroundImageMo + ')'}">
    <div class="container" :class="[ fullWidth > 768 ? 'containerSamll':'containerBig']">
      <template v-if="fullWidth>768">
        <img :src="titleImg" class="title-img"/>
        <div class="swiper-button-prev swiper-button-prev2"></div>
        <swiper :options="swiperOption" class="swiperPross">
          <swiper-slide v-for="(item,index) in leftSwiperList" :key="index" class="swiperPic">
            <app-link :to="resolvePath(item.url)">
              <div class="enter-box">
                <img :src="item.pic" class="enter-img">
                <div class="enter-title">{{item.name}}</div>
                <div class="enter-desc">{{item.desc}}</div>
              </div>
            </app-link>
<!--            <img :src="item.pic">-->
          </swiper-slide>
          <div slot="pagination" class="swiper-pagination"/>
        </swiper>
        <div class="swiper-button-next swiper-button-next2"></div>
      </template>
    </div>
  </div>
</template>

<script>
import { checkPermi } from "@/utils/permission"; // 权限判断函数
import "@/assets/js/canvas-nest.min.js";
import {isExternal} from "@/utils/validate";
import path from "path";
import AppLink from '@/layout/components/Sidebar/Link'
export default {
  name: 'Enter',
  components: { AppLink },
  data() {
    return {
      swiperList: [
        {id:1,name:"首页",desc:"Home page",pic: require("@/assets/imgs/enter/dashboard.png"),url:"/dashboard"},
        {id:110,name:"消息通知",desc:"Message notice",pic: require("@/assets/imgs/enter/message.png"),url:"/Message/index"},
        {id:228,name:"年度工作计划",desc:"Message notice",pic: require("@/assets/imgs/enter/yearTask.png"),url:"/yearTask/index"},
        {id:158,name:"大纲-报告-项目-研究",desc:"Task progress",pic: require("@/assets/imgs/enter/task.png"),url:"/task/index"},
        {id:158,name:"教育管理",desc:"Task progress",pic: require("@/assets/imgs/enter/other.png"),url:"/other/index"},
        {id:149,name:"政治工作",desc:"Political work",pic: require("@/assets/imgs/enter/zhenggong.png"),url:"/department/index"},
        {id:150,name:"军事训练",desc:"Military affairs",pic: require("@/assets/imgs/enter/junshi.png"),url:"/person/material"},
        {id:174,name:"试验任务",desc:"Experimental information",pic: require("@/assets/imgs/enter/tests.png"),url:"/tests/index"},
        {id:151,name:"保密",desc:"Keep secrecy",pic: require("@/assets/imgs/enter/baomi.png"),url:"/electronic/index"},
        {id:152,name:"后勤",desc:"Logistics work",pic: require("@/assets/imgs/enter/houqing.png"),url:"/car/index"},
        {id:10,name:"系统设置",desc:"System setting",pic: require("@/assets/imgs/enter/config.png"),url:"/operation/siteConfig"},
        {id:79,name:"维护",desc:"Maintain files",pic: require("@/assets/imgs/enter/maintain.png"),url:"/maintain/picture"},
      ],
      backgroundImages: '',
      backgroundImageMo: require("@/assets/imgs/bg.jpg"),//默认背景图
      titleImg: require("@/assets/imgs/enter/title.png"),
      fullWidth: document.body.clientWidth,
      swiperOption: {
        pagination: {
          el: '.swiper-pagination'
        },
        //显示分页
        //loop: false,
        //开启循环
        //loopedSlides: 4,
        //设置平滑
        slidesPerView: 4,
        autoplay: {
          enabled: false,
          disableOnInteraction: false,
          delay: 3000
        },
        navigation: {
          prevEl: ".swiper-button-prev2",
          nextEl: ".swiper-button-next2"
        },
      },
      capsTooltip: false,
      showDialog: false,
    }
  },
  computed:{
    leftSwiperList(){
      let permissionRoutes = this.$store.getters.permission_routes
      let userPermissionIds = []
      permissionRoutes.forEach((item)=>{
        userPermissionIds.push(item.id)
      })

      permissionRoutes = this.swiperList.filter((p)=>{
        return userPermissionIds.indexOf(p.id) !== -1
      })
      return permissionRoutes;
    }
  },
  watch: {
    fullWidth(val) {
      // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
      if (!this.timer) {
        // 一旦监听到的screenWidth值改变，就将其重新赋给data里的screenWidth
        this.screenWidth = val
        this.timer = true
        const that = this
        setTimeout(function () {
          // 打印screenWidth变化的值
          that.timer = false
        }, 400)
      }
    },
  },

  //生命周期1 创建前
  beforeCreate() {
    if (this.fullWidth < 768) {
      document
        .getElementsByTagName("canvas")[0]
        .removeAttribute("class", "index_bg");
    } else {
      //document.getElementsByTagName("canvas")[0].className = "index_bg";//背景canvas
    }
  },
  //生命周期2 创建后
  created() {
    window.addEventListener('resize', this.handleResize)
  },
  //生命周期3 载入后（挂载数据完成后）
  mounted() {
    //console.log(this.leftSwiperList)
    this.$nextTick(() => {
      if (this.screenWidth < 768) {
        document
          .getElementsByTagName("canvas")[0]
          .removeAttribute("class", "index_bg");
      } else {
        //document.getElementsByTagName("canvas")[0].className = "index_bg";//背景canvas
      }
    });
  },
  //生命周期4 销毁前
  beforeDestroy: function () {
    window.removeEventListener('resize', this.handleResize)
    document
      .getElementsByTagName("canvas")[0]
      .removeAttribute("class", "index_bg");
  },
  //生命周期5 销毁后
  destroyed() {
    // window.removeEventListener('storage', this.afterQRScan)
  },

  methods:{
    checkPermi,

    //处理screen尺寸变化
    handleResize(event) {
      this.fullWidth = document.body.clientWidth
      if (this.fullWidth < 768) {
        document
          .getElementsByTagName("canvas")[0]
          .removeAttribute("class", "index_bg");
      } else {
        //document.getElementsByTagName("canvas")[0].className = "index_bg";//背景canvas
      }
    },

    resolvePath(routePath) {
      if (isExternal(routePath)) {
        return routePath
      }
      if (isExternal(this.basePath)) {
        return this.basePath
      }
      return path.resolve(this.basePath, routePath)
    }
  },
}
</script>

<style lang="scss" scoped>
$screen-md: 768px;
$font-size-base: 14px;
$animation-time: .3s;
$animation-time-quick: .15s;
$transition-time: .2s;
$ease-in-out: ease-in-out;
$subsidiary-color: #808695;
.footer {
  align-items: center;
  justify-content: center;
  width: 50%;
  height: 36px;
  cursor: pointer;
}

.wechat {
  width: 26px;
  height: 26px;

  img {
    width: 100%;
    height: 100%;
  }
}

.page-account {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  overflow: auto;

  &-container {
    flex: 1;
    padding: 32px 0;
    text-align: center;
    width: 384px;
    margin: 0 auto;

    &-result {
      width: 100%;
    }
  }

  &-tabs {
    .ivu-tabs-bar {
      border-bottom: none;
    }

    .ivu-tabs-nav-scroll {
      text-align: center;
    }

    .ivu-tabs-nav {
      display: inline-block;
      float: none;
    }
  }

  &-top {
    padding: 32px 0;

    &-logo {
      img {
        max-height: 75px;
      }
    }

    &-desc {
      font-size: $font-size-base;
      color: $subsidiary-color;
    }
  }

  &-auto-login {
    margin-bottom: 24px;
    text-align: left;

    a {
      float: right;
    }
  }

  &-other {
    margin: 24px 0;
    text-align: left;

    span {
      font-size: $font-size-base;
    }

    img {
      width: 24px;
      margin-left: 16px;
      cursor: pointer;
      vertical-align: middle;
      opacity: 0.7;
      transition: all $transition-time $ease-in-out;

      &:hover {
        opacity: 1;
      }
    }
  }

  .ivu-poptip, .ivu-poptip-rel {
    display: block;
  }

  &-register {
    float: right;

    &-tip {
      text-align: left;

      &-title {
        font-size: $font-size-base;
      }

      &-desc {
        white-space: initial;
        font-size: $font-size-base;
        margin-top: 6px;
      }
    }
  }

  &-to-login {
    text-align: center;
    margin-top: 16px;
  }

  &-header {
    text-align: right;
    position: fixed;
    top: 16px;
    right: 24px;
  }
}

.labelPic {
  position: absolute;
  right: 0;
}

::v-deep .swiper-pagination-bullet{
  color:#fff;
  background-color: #FFFFFF;

}
::v-deep .swiper-pagination-bullet-active {
  opacity: 1;
  background-color: #FFFFFF;
}
::v-deep .swiper-button-next,::v-deep .swiper-button-prev{
  border:3px solid #498ff8;
  border-radius:10px;
  width:50px;
  height:70px;
  background-size:20px 30px;
  margin-top:-25px;
}

@media (min-width: $screen-md) {
  .page-account {
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
  }
  .page-account-container {
    padding: 32px 0 24px 0;
    position: relative;
  }
}

.page-account {
  display: flex;
}

.page-account .code {
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-account .code .pictrue {
  height: 40px;
}

.swiperPross {
  border-radius: 6px 0px 0px 6px;
  overflow: hidden;
}

.swiperPross, .swiperPic, .swiperPic img {
  width: 100%;
  height: 100%;
}

.swiperPic img {
  width: 100%;
  height: 100%;
}

.title-img{
  display:block;
  width:360px;
  height:60px;
  position: absolute;
  top:15vh;
  left:0;
  right:0;
  margin: 0 auto;
}

.container {
  height: 420px !important;
  padding: 0 !important;
  /*overflow: hidden;*/
  border-radius: 6px;
  z-index: 1;
  display: flex;
  margin-top:11vh;

  .enter-box{
    width:250px;
    height:350px;
    border-radius: 4px;
    color:#fff;
    border:2px solid #498ff8;
    display:flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: 0px 0px 50px 0px #498ff8 inset;
    cursor: pointer;

    .enter-img{
      width:70px;
      height:70px;
      margin-bottom:60px;
    }
    .enter-title{
      font-size:24px;
      margin-bottom:15px;
    }
    .enter-desc{
      font-size:20px;
    }
  }
  .enter-box:hover{
    box-shadow: 0px 0px 200px 10px #498ff8 inset;
  }
}

.containerSamll {
  /*width: 56% !important;*/
  width: 1150px;
  //background: #fff !important;
}

.containerBig {
  width: auto !important;
  //background: #f7f7f7 !important;
}

.index_from {
  width: 384px;
  padding: 0 40px 32px 40px;
  height: 400px;
  box-sizing: border-box;
}

.page-account-top {
  margin: 20px 0 !important;
  padding: 20px 0 !important;
  box-sizing: border-box !important;
  display: flex;
  justify-content: center;
}

.page-account-container {
  border-radius: 0px 6px 6px 0px;
}

.btn {
  background: linear-gradient(90deg, rgba(25, 180, 241, 1) 0%, rgba(14, 115, 232, 1) 100%) !important;
}
</style>

<style lang="scss" scoped>
.captcha {
  display: flex;
  align-items: flex-start;
}

$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.imgs {
  img {
    height: 36px;
  }
}

.login-form {
  position: relative;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.tips {
  font-size: 14px;
  color: #fff;
  margin-bottom: 10px;

  span {
    &:first-of-type {
      margin-right: 16px;
    }
  }
}

.svg-container {
  padding: 6px 5px 6px 15px;
  color: $dark_gray;
  vertical-align: middle;
  width: 30px;
  display: inline-block;
}

.show-pwd {
  position: absolute;
  right: 10px;
  top: 7px;
  font-size: 16px;
  color: $dark_gray;
  cursor: pointer;
  user-select: none;

  ::v-deep.svg-icon {
    vertical-align: 0.3em;
  }
}

.thirdparty-button {
  position: absolute;
  right: 0;
  bottom: 6px;
}
</style>
